package com.sun.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sun.entity.Category;
import com.sun.entity.R;
import com.sun.mapper.CategoryMapper;
import com.sun.service.ICategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author SunRui
 * @since 2025-01-13
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements ICategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public R insert(Category category) {
        return R.success(categoryMapper.insert(category));
    }

    @Override
    public R delete(Integer id) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("id",id);
        return R.success(categoryMapper.delete(queryWrapper));
    }

    @Override
    public int update(Category category) {
        return categoryMapper.updateById(category);
    }

    @Override
    public R selectAll(Integer page,Integer size) {
        Page pages = new Page<>(page,size);
        return R.success(categoryMapper.selectPage(pages));
    }

    @Override
    public R selectByName(String name, Integer page, Integer size) {
        Page pages = new Page<>(page,size);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.like("name",name);
        return R.success(categoryMapper.selectMapsPage(pages,queryWrapper));
    }


}
